<?php


abstract class BaseTallerSesion extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $taller_id;


	
	protected $unidad_id;


	
	protected $num_horas;


	
	protected $observaciones;


	
	protected $lugar;


	
	protected $cupos;


	
	protected $fecha_inicio;


	
	protected $fecha_final;


	
	protected $hora_inicio;


	
	protected $status;

	
	protected $aTaller;

	
	protected $aUnidad;

	
	protected $collInvitadoTallers;

	
	protected $lastInvitadoTallerCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getTallerId()
	{

		return $this->taller_id;
	}

	
	public function getUnidadId()
	{

		return $this->unidad_id;
	}

	
	public function getNumHoras()
	{

		return $this->num_horas;
	}

	
	public function getObservaciones()
	{

		return $this->observaciones;
	}

	
	public function getLugar()
	{

		return $this->lugar;
	}

	
	public function getCupos()
	{

		return $this->cupos;
	}

	
	public function getFechaInicio($format = 'Y-m-d')
	{

		if ($this->fecha_inicio === null || $this->fecha_inicio === '') {
			return null;
		} elseif (!is_int($this->fecha_inicio)) {
						$ts = strtotime($this->fecha_inicio);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_inicio] as date/time value: " . var_export($this->fecha_inicio, true));
			}
		} else {
			$ts = $this->fecha_inicio;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getFechaFinal($format = 'Y-m-d')
	{

		if ($this->fecha_final === null || $this->fecha_final === '') {
			return null;
		} elseif (!is_int($this->fecha_final)) {
						$ts = strtotime($this->fecha_final);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_final] as date/time value: " . var_export($this->fecha_final, true));
			}
		} else {
			$ts = $this->fecha_final;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getHoraInicio($format = 'H:i:s')
	{

		if ($this->hora_inicio === null || $this->hora_inicio === '') {
			return null;
		} elseif (!is_int($this->hora_inicio)) {
						$ts = strtotime($this->hora_inicio);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [hora_inicio] as date/time value: " . var_export($this->hora_inicio, true));
			}
		} else {
			$ts = $this->hora_inicio;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getStatus()
	{

		return $this->status;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TallerSesionPeer::ID;
		}

	} 
	
	public function setTallerId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->taller_id !== $v) {
			$this->taller_id = $v;
			$this->modifiedColumns[] = TallerSesionPeer::TALLER_ID;
		}

		if ($this->aTaller !== null && $this->aTaller->getId() !== $v) {
			$this->aTaller = null;
		}

	} 
	
	public function setUnidadId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->unidad_id !== $v) {
			$this->unidad_id = $v;
			$this->modifiedColumns[] = TallerSesionPeer::UNIDAD_ID;
		}

		if ($this->aUnidad !== null && $this->aUnidad->getId() !== $v) {
			$this->aUnidad = null;
		}

	} 
	
	public function setNumHoras($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->num_horas !== $v) {
			$this->num_horas = $v;
			$this->modifiedColumns[] = TallerSesionPeer::NUM_HORAS;
		}

	} 
	
	public function setObservaciones($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->observaciones !== $v) {
			$this->observaciones = $v;
			$this->modifiedColumns[] = TallerSesionPeer::OBSERVACIONES;
		}

	} 
	
	public function setLugar($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->lugar !== $v) {
			$this->lugar = $v;
			$this->modifiedColumns[] = TallerSesionPeer::LUGAR;
		}

	} 
	
	public function setCupos($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->cupos !== $v) {
			$this->cupos = $v;
			$this->modifiedColumns[] = TallerSesionPeer::CUPOS;
		}

	} 
	
	public function setFechaInicio($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_inicio] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_inicio !== $ts) {
			$this->fecha_inicio = $ts;
			$this->modifiedColumns[] = TallerSesionPeer::FECHA_INICIO;
		}

	} 
	
	public function setFechaFinal($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_final] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_final !== $ts) {
			$this->fecha_final = $ts;
			$this->modifiedColumns[] = TallerSesionPeer::FECHA_FINAL;
		}

	} 
	
	public function setHoraInicio($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [hora_inicio] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->hora_inicio !== $ts) {
			$this->hora_inicio = $ts;
			$this->modifiedColumns[] = TallerSesionPeer::HORA_INICIO;
		}

	} 
	
	public function setStatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->status !== $v) {
			$this->status = $v;
			$this->modifiedColumns[] = TallerSesionPeer::STATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->taller_id = $rs->getInt($startcol + 1);

			$this->unidad_id = $rs->getInt($startcol + 2);

			$this->num_horas = $rs->getInt($startcol + 3);

			$this->observaciones = $rs->getString($startcol + 4);

			$this->lugar = $rs->getString($startcol + 5);

			$this->cupos = $rs->getInt($startcol + 6);

			$this->fecha_inicio = $rs->getDate($startcol + 7, null);

			$this->fecha_final = $rs->getDate($startcol + 8, null);

			$this->hora_inicio = $rs->getTime($startcol + 9, null);

			$this->status = $rs->getString($startcol + 10);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TallerSesion object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TallerSesionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TallerSesionPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TallerSesionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTaller !== null) {
				if ($this->aTaller->isModified()) {
					$affectedRows += $this->aTaller->save($con);
				}
				$this->setTaller($this->aTaller);
			}

			if ($this->aUnidad !== null) {
				if ($this->aUnidad->isModified()) {
					$affectedRows += $this->aUnidad->save($con);
				}
				$this->setUnidad($this->aUnidad);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TallerSesionPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TallerSesionPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collInvitadoTallers !== null) {
				foreach($this->collInvitadoTallers as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTaller !== null) {
				if (!$this->aTaller->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTaller->getValidationFailures());
				}
			}

			if ($this->aUnidad !== null) {
				if (!$this->aUnidad->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUnidad->getValidationFailures());
				}
			}


			if (($retval = TallerSesionPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collInvitadoTallers !== null) {
					foreach($this->collInvitadoTallers as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TallerSesionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getTallerId();
				break;
			case 2:
				return $this->getUnidadId();
				break;
			case 3:
				return $this->getNumHoras();
				break;
			case 4:
				return $this->getObservaciones();
				break;
			case 5:
				return $this->getLugar();
				break;
			case 6:
				return $this->getCupos();
				break;
			case 7:
				return $this->getFechaInicio();
				break;
			case 8:
				return $this->getFechaFinal();
				break;
			case 9:
				return $this->getHoraInicio();
				break;
			case 10:
				return $this->getStatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TallerSesionPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getTallerId(),
			$keys[2] => $this->getUnidadId(),
			$keys[3] => $this->getNumHoras(),
			$keys[4] => $this->getObservaciones(),
			$keys[5] => $this->getLugar(),
			$keys[6] => $this->getCupos(),
			$keys[7] => $this->getFechaInicio(),
			$keys[8] => $this->getFechaFinal(),
			$keys[9] => $this->getHoraInicio(),
			$keys[10] => $this->getStatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TallerSesionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setTallerId($value);
				break;
			case 2:
				$this->setUnidadId($value);
				break;
			case 3:
				$this->setNumHoras($value);
				break;
			case 4:
				$this->setObservaciones($value);
				break;
			case 5:
				$this->setLugar($value);
				break;
			case 6:
				$this->setCupos($value);
				break;
			case 7:
				$this->setFechaInicio($value);
				break;
			case 8:
				$this->setFechaFinal($value);
				break;
			case 9:
				$this->setHoraInicio($value);
				break;
			case 10:
				$this->setStatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TallerSesionPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setTallerId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUnidadId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setNumHoras($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setObservaciones($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setLugar($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setCupos($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setFechaInicio($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setFechaFinal($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setHoraInicio($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setStatus($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TallerSesionPeer::DATABASE_NAME);

		if ($this->isColumnModified(TallerSesionPeer::ID)) $criteria->add(TallerSesionPeer::ID, $this->id);
		if ($this->isColumnModified(TallerSesionPeer::TALLER_ID)) $criteria->add(TallerSesionPeer::TALLER_ID, $this->taller_id);
		if ($this->isColumnModified(TallerSesionPeer::UNIDAD_ID)) $criteria->add(TallerSesionPeer::UNIDAD_ID, $this->unidad_id);
		if ($this->isColumnModified(TallerSesionPeer::NUM_HORAS)) $criteria->add(TallerSesionPeer::NUM_HORAS, $this->num_horas);
		if ($this->isColumnModified(TallerSesionPeer::OBSERVACIONES)) $criteria->add(TallerSesionPeer::OBSERVACIONES, $this->observaciones);
		if ($this->isColumnModified(TallerSesionPeer::LUGAR)) $criteria->add(TallerSesionPeer::LUGAR, $this->lugar);
		if ($this->isColumnModified(TallerSesionPeer::CUPOS)) $criteria->add(TallerSesionPeer::CUPOS, $this->cupos);
		if ($this->isColumnModified(TallerSesionPeer::FECHA_INICIO)) $criteria->add(TallerSesionPeer::FECHA_INICIO, $this->fecha_inicio);
		if ($this->isColumnModified(TallerSesionPeer::FECHA_FINAL)) $criteria->add(TallerSesionPeer::FECHA_FINAL, $this->fecha_final);
		if ($this->isColumnModified(TallerSesionPeer::HORA_INICIO)) $criteria->add(TallerSesionPeer::HORA_INICIO, $this->hora_inicio);
		if ($this->isColumnModified(TallerSesionPeer::STATUS)) $criteria->add(TallerSesionPeer::STATUS, $this->status);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TallerSesionPeer::DATABASE_NAME);

		$criteria->add(TallerSesionPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setTallerId($this->taller_id);

		$copyObj->setUnidadId($this->unidad_id);

		$copyObj->setNumHoras($this->num_horas);

		$copyObj->setObservaciones($this->observaciones);

		$copyObj->setLugar($this->lugar);

		$copyObj->setCupos($this->cupos);

		$copyObj->setFechaInicio($this->fecha_inicio);

		$copyObj->setFechaFinal($this->fecha_final);

		$copyObj->setHoraInicio($this->hora_inicio);

		$copyObj->setStatus($this->status);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getInvitadoTallers() as $relObj) {
				$copyObj->addInvitadoTaller($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TallerSesionPeer();
		}
		return self::$peer;
	}

	
	public function setTaller($v)
	{


		if ($v === null) {
			$this->setTallerId(NULL);
		} else {
			$this->setTallerId($v->getId());
		}


		$this->aTaller = $v;
	}


	
	public function getTaller($con = null)
	{
				include_once 'lib/model/om/BaseTallerPeer.php';

		if ($this->aTaller === null && ($this->taller_id !== null)) {

			$this->aTaller = TallerPeer::retrieveByPK($this->taller_id, $con);

			
		}
		return $this->aTaller;
	}

	
	public function setUnidad($v)
	{


		if ($v === null) {
			$this->setUnidadId(NULL);
		} else {
			$this->setUnidadId($v->getId());
		}


		$this->aUnidad = $v;
	}


	
	public function getUnidad($con = null)
	{
				include_once 'lib/model/om/BaseUnidadPeer.php';

		if ($this->aUnidad === null && ($this->unidad_id !== null)) {

			$this->aUnidad = UnidadPeer::retrieveByPK($this->unidad_id, $con);

			
		}
		return $this->aUnidad;
	}

	
	public function initInvitadoTallers()
	{
		if ($this->collInvitadoTallers === null) {
			$this->collInvitadoTallers = array();
		}
	}

	
	public function getInvitadoTallers($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseInvitadoTallerPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collInvitadoTallers === null) {
			if ($this->isNew()) {
			   $this->collInvitadoTallers = array();
			} else {

				$criteria->add(InvitadoTallerPeer::TALLER_SESION_ID, $this->getId());

				InvitadoTallerPeer::addSelectColumns($criteria);
				$this->collInvitadoTallers = InvitadoTallerPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(InvitadoTallerPeer::TALLER_SESION_ID, $this->getId());

				InvitadoTallerPeer::addSelectColumns($criteria);
				if (!isset($this->lastInvitadoTallerCriteria) || !$this->lastInvitadoTallerCriteria->equals($criteria)) {
					$this->collInvitadoTallers = InvitadoTallerPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastInvitadoTallerCriteria = $criteria;
		return $this->collInvitadoTallers;
	}

	
	public function countInvitadoTallers($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseInvitadoTallerPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(InvitadoTallerPeer::TALLER_SESION_ID, $this->getId());

		return InvitadoTallerPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addInvitadoTaller(InvitadoTaller $l)
	{
		$this->collInvitadoTallers[] = $l;
		$l->setTallerSesion($this);
	}

} 